<template>
  <div class="purchasePage">
    <el-table :data="data" style="width: 100%" border v-loading="loading">
      <el-table-column prop="id" label="编号" width="200"> </el-table-column>
      <el-table-column prop="title" label="采购标题" width="200">
      </el-table-column>
      <el-table-column
        prop="content"
        label="采购内容"
        width="300"
        show-overflow-tooltip
        :append-to-body="false"
      >
        <template slot-scope="{ row }">
          <div
            style="
              overflow: hidden;
              width: 100%;
              white-space: nowrap;
              text-overflow: ellipsis;
            "
          >
            {{ row.content }}
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="buyPrice" label="采购价格" width="200">
        <template slot-scope="{ row }">
          <div>{{ formatCurrency(row.buyPrice, 2) }}</div>
        </template>
      </el-table-column>
      <el-table-column prop="buyDate" label="日期" width="200">
      </el-table-column>
      <el-table-column prop="buyURL" label="文件地址" width="200">
      </el-table-column>
      <el-table-column prop="author" label="发布者" width="200">
      </el-table-column>
      <el-table-column prop="status" label="发布状态" width="200">
        <template slot-scope="{ row }">
          <el-tag v-if="row.status == 0" type="info">未发布</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="control" :fixed="'right'" label="操作栏" width="300">
        <template slot-scope="{ row }">
          <el-button type="primary" size="small" @click="lookdetail(row.id)"
            >详情</el-button
          >
          <el-button type="warning" size="small" @click="edit(row)"
            >修改</el-button
          >
          <el-button type="danger" size="small" @click="public(row)"
            >发布</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  props: ["data", "loading"],
  methods: {
    lookdetail(e) {
      //跳转
      this.$router.push({
        path: "/purchase/lookBuy",
        query: {
          id: e,
        },
      });
    },
    //编辑
    edit(e) {
      this.$router.push({
        path: "/purchase/editBuy",
        query: {
          row: this.$Base64.encode(JSON.stringify(e)),
        },
      });
    },
    //转化金额
    formatCurrency(amount, decimalPlaces) {
      // 确保金额是数字
      const number = Number(amount);
      // 使用toFixed()方法确定小数位数
      const formatted = number.toFixed(decimalPlaces);
      // 返回格式化后的金额字符串
      return formatted;
    },
    //发布
    public(e){
      this.$http.post('/publicPurchase',{id:e.id}).then(res=>{
        if(res.code==200){
          this.$message.success('发布成功')
        }
        else{
          this.$message.error(res.msg)
        }
      })
    }
  },
};
</script>

<!-- 单独写个css -->
<style lang="css">
.el-tooltip__popper {
  width: 500px;
}
</style>